//
//  EvaluationTableViewCell.m
//  SeaMelonSeeds_Counselor
//
//  Created by 尤振宇 on 2017/8/9.
//  Copyright © 2017年 杨笑. All rights reserved.
//

#import "EvaluationTableViewCell.h"
#import <Masonry.h>

@interface EvaluationTableViewCell()
{
    UIView *_starView;
}
@end

@implementation EvaluationTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;

    _starView = [[UIView alloc]init];
    UIImage *star = [UIImage imageNamed:@"StarIcon"];
    [self.contentView addSubview:_starView];
    int count = 5;
    for (int i = 0; i < count; i++) {
        UIImageView *imageView = [[UIImageView alloc]init];
        imageView.image = star;
        [_starView addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(_starView);
            make.height.equalTo(@(star.size.height));
            make.width.equalTo(@(star.size.width));
            make.left.equalTo(@(star.size.width * i));
        }];
        
        if (i == count - 1) {
            [_starView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(self.name);
                make.width.equalTo(@(count * star.size.width));
                make.height.equalTo(@(star.size.height));
                make.left.equalTo(self.name.mas_right).with.offset(10);
            }];
        }
    }
}

-(void)starScore:(float)score
{
    UIImage *star = [UIImage imageNamed:@"StarIcon"];
    BOOL hidden = NO;
    int count = ceilf(score);
    for (int i = 0; i<_starView.subviews.count; i++) {
        UIImageView *imageView = [_starView.subviews objectAtIndex:i];
        imageView.image = star;
        imageView.hidden = hidden;
        
        if (i == count-1) {
            if (count - score != 0) {
                imageView.image = [UIImage imageNamed:@"HalfStar"];
            }
            hidden = YES;
        }
    }
}

@end
